<?php
class arcController extends Controller{
	
	public function __construct(){
		parent::__construct();
		
	}
	public function s(){
		return array('arc');
	}
	public function index(){
	
	}
    public function mylist(){
        $condition=array();
		$extra='';
        
        $level_id=intval($_GET['level_id']);
        if(!in_array($level_id,range(1,12))) exit;
        
        $condition['level_id']=$level_id;
        $extra.=" and `level_id`='{$level_id}' ";
        
        $CAT=$this->s_0->get_cat_detail($level_id);
        
		$return=$this->s_0->mylist($condition,$extra);
		include($this->viewer_dir.'arc/mylist.php');
    }
    public function show(){
        $id=intval($_GET['id']);
        if($id>0){
            $item=(array) $this->s_0->show($id);
            if(!empty($item)){
                $this->s_0->update_arc_hits($id);
                $object=load_service('a_show',P_SVC);
                include($this->viewer_dir.'arc/show.php');
            }
        }
    }
	
	
	public function favorite(){
		$echo=array('code'=>1,'msg'=>'文章收藏成功！');
		$id=intval($_POST['id']);
		if($id<=0){
			$echo['code']=-1;
			$echo['msg']='文章id错误！';
			echo json_encode($echo);
			exit;
		}
		//检查登陆
		if(!isset($_SESSION['MY']['UID']) || intval($_SESSION['MY']['UID'])<=0){
			$echo['code']=-2;
			$echo['msg']='登陆后才可以收藏文章！';
			echo json_encode($echo);
			exit;
		}
		$r=$this->s_0->favorite($id);
		if(!$r){
			$echo['code']=-1;
			$echo['msg']='文章id错误！';
			echo json_encode($echo);
			exit;
		}
		$t=$this->s_0->favorite_($id,$_SESSION['MY']['UID'],array('title'=>$r['title'],'htmlurl'=>$r['htmlurl']));
		if(!$t){
			$echo['code']=-3;
			$echo['msg']='文章收藏失败！';
			echo json_encode($echo);
			exit;
		}
		echo json_encode($echo);
		exit;
	}
	
//
}